﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Threading;
using System.Net.NetworkInformation;
using System.Net;

using NetCard.Models;
using System.Text;
using NetCard.Controllers;


namespace NetCard
{

    public class Pinger
    {
        private Router routerToTest;
        private PingModel pingmdl;


        public Pinger(Router routerToTest, PingModel pingmdl)
        {
            this.routerToTest = routerToTest;
            this.pingmdl = pingmdl;
        }

        public PingReply Ping()
        {
            AutoResetEvent waiter = new AutoResetEvent(false);

            Ping pingSender = new Ping();

            string who = pingmdl.Ip;

            PingOptions options = new PingOptions(pingmdl.Ttl, true);
            string data = "";
            for (int i = 0; i < pingmdl.Size; i++)
            {
                data += "a";
            }
            byte[] buffer = Encoding.ASCII.GetBytes(data);
            int timeOut = pingmdl.TimeOut;

            PingReply reply = pingSender.Send(who, timeOut, buffer, options);
            return reply;
        }


    }
}